# -*- encoding=UTF-8 -*-

from now import app, db
from flask_script import Manager
from now.models import User, Image, Comment
import random
manager = Manager(app)


def get_image_url():
    return '/static/images/img/1 (' + str(random.randint(1, 18)) + ').jpg'

@manager.command
def init_database():
    db.drop_all()
    db.create_all()

    for i in range(0, 100):
        db.session.add(User('user'+str(i), random.randint(1000, 9999)))
        for j in range(0, 5):
            db.session.add(Image(get_image_url(), i+1))
            for k in range(0, 3):
                db.session.add(Comment('这是评论'+str(k), 1+5*i+j, i+1))

    db.session.commit()


if __name__ == '__main__':
    manager.run()